<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%
 	String path = request.getContextPath();
 	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
 	request.setAttribute("path", path);
 	request.setAttribute("jsPath", path+"/js");
 	request.setAttribute("cssPath", path+"/css");
 	request.setAttribute("imagePath", path+"/image");
 %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<script src="/js/jquery-2.1.1.min.js"></script>
	
	<link href="/css/bootstrap.min.css?v=3.4.0" rel="stylesheet">
	<link href="/css/font-awesome.css?v=4.3.0" rel="stylesheet">
	<link href="/css/morris-0.4.3.min.css" rel="stylesheet">
	<!-- Gritter -->
	<link href="/css/jquery.gritter.css" rel="stylesheet">
	<link href="/css/animate.css" rel="stylesheet">
	<link href="/css/style.css?v=2.2.0" rel="stylesheet">
	<script type="text/javascript">
		$(function(){
			
			 $("input[name=allselect]").click(function(){
	             if($(this).prop("checked")==true){
	                 $("input[name=select]").prop("checked","true");
	             }else{
	                 $("input[name=select]").prop("checked","");
	             }
	         }) ;
			
		});
		
		function roleAddSubmit(){
			$('#RoleAddFrom').submit();
		}
		
		function search(){
			$("#FunPageNum").val(1);
			$("#SysPageNum").val(1);
			$('#querySysRole').submit();
		}
		
		function FunGoPage(pageNum){
			$("#FunPageNum").val(pageNum);
			$('#querySysRole').submit();
		}
		
		function SysGoPage(pageNum){
			$("#SysPageNum").val(pageNum);
			$('#querySysRole').submit();
		}
		
		
		function peiQuan(){
			var peiQuanArray=[];
			var sysRoleId=$("input[id=roleId]").val();
			$("input[name=select]:checked").each(function(){
				peiQuanArray.push($(this).val());
			});
			$.ajax({
				type:"post",
				url:"<%=basePath %>RoleAuthority/add",
				data:{"dat":peiQuanArray,"sysRoleId":sysRoleId},
				success:function(data){
					 if(data=="true"){
						window.location.href="<%=basePath %>Sysrole/show";
					}
					if(data=="false"){
						alert("不可重复分配资源");
					} 
				}
			})

		}
	</script>
	<style type="text/css">
		#SysRole{
			width:200px;
			height:200px;
			float:left;
			margin:50px;
		}
		#FunctionAuthority{
			width:200px;
			height:200px;
			float:left;
			margin:50px;
		}
		
		#tableHeight{
			height:150px;
		}
		
		.pagination{
		  	margin:20px;
		}
		
	</style>
</head>
<body>
		<div id="wrapper">
		
		<!-- 左边导航 -->
		<%@ include file="../share/leftMenu.jsp" %>
				
		<div id="page-wrapper" class="gray-bg dashbard-1">
		<!-- 头部 -->
		<%@ include file="../share/head.jsp" %>

	<h1>资源权限分配</h1>
	<form id="querySysRole" action="<%=basePath %>Sysrole/showAddBySysRoleId" method="get">
			<label style="margin-left:300px;">资源名：</label><input type="text" name="FunName" value="${functionauthorityInfo.name }"/> 
			<input type="hidden" id="FunPageNum" name="FunPageNum" value="${funPage.pageNo}"/>
			<input type="hidden" id="roleId" name="roleId" value="${SysInfo.roleId }"/> 
			<input type="button" value="查询" onclick="search()"/>
		</form>
	<div id="SysRole">	
		<h3>需要分配的角色名</h3><input id="SysName" value="${SysInfo.name }" type="text" readonly="readonly"/>
	</div>
	
	<div id="FunctionAuthority">
		<div id="tableHeight">
		<h3>需要分配的资源列表</h3>
		<c:if test="${empty funs}">
				<h3>您好，没有符合的信息！</h3>
			</c:if>
			<c:if test="${!empty funs}">
		<table style="margin:10px;text-align:center;">
			<thead>
				<tr>
					<th><input type="checkbox" name="allselect" value="1">全选</th>
					<th>序号</th>
					<th>资源名称</th>
				</tr>
			</thead>
			<tbody>
			
				 <c:forEach var="f" items="${funs }" varStatus="status">
				 	<tr>
				 		<td><input type="checkbox" name="select" value="${f.functionauthorityId }"></td>
				 		<td>${status.index+1 }</td>
				 		<td>${f.name }</td>
				 	</tr>
				 </c:forEach> 
			
			</tbody>
		</table>
		</c:if>
		</div>
	        	<ul class="pagination">
	        	<c:forEach var="i" begin="1" end="${funPage.pages}">
											<li class="paginate_button">
						                    <a href="javaScript:void(0)" 
						                    aria-controls="example2" data-dt-idx="${i}" tabindex="0" onclick="FunGoPage(${i})">${i}</a></li>
					</c:forEach>
			</ul>
		<input type="button" value="提交" onclick="peiQuan()"/>
	</div>
		<form id="RoleAddFrom" action="<%=basePath %>RoleAuthority/add" method="get">
			<input type="hidden" name="roleId" value=""/>
			<input type="hidden" name="functionauthorityId" value=""/>
		</form>
	</div>
</body>
</html>